package com.thon.entity.topic;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.thon.commons.persistence.IdEntity;
import com.thon.entity.system.User;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * Created by Chen on 2016/2/10.
 */
@Entity
@Table(name = "to_choice")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Choice extends IdEntity {

    private Date choiceDate;    //选题时间
    private Integer status = 0;     //状态：0等待教师审核/1教师审查通过/2未通过教师审核/3教务审查通过/4未通过教务审核

    private User student;    //选题学生
    private Topic topic;     //所选题目

    public Choice(){
        setChoiceDate(new Date());
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    public Date getChoiceDate() {
        return choiceDate;
    }

    public void setChoiceDate(Date choiceDate) {
        this.choiceDate = choiceDate;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="student_id")
    @NotFound(action=NotFoundAction.IGNORE)
    public User getStudent() {
        return student;
    }

    public void setStudent(User student) {
        this.student = student;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="topic_id")
    @NotFound(action=NotFoundAction.IGNORE)
    public Topic getTopic() {
        return topic;
    }

    public void setTopic(Topic topic) {
        this.topic = topic;
    }

}
